package com.example.demo.init;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.demo.entity.Account;
import com.example.demo.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class DatabaseInit {

    private static final String USER_ID = "U100001";

    @Autowired
    private AccountService accountService;

    @PostConstruct
    public void init() {
        accountService.remove(new LambdaQueryWrapper<Account>().eq(Account::getUserId, USER_ID));
        Account account = new Account();
        account.setId(IdUtil.getSnowflakeNextId());
        account.setUserId(USER_ID);
        account.setMoney(10000);
        accountService.save(account);
    }

}
